package com.ytxx.fit.project.conf;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;


/**
* 资源拦截配置
* @Param:
* @return:
* @Author: sxm09
* @date: 2022/3/1
*/

@Configuration
public class InterceptorConf extends WebMvcConfigurationSupport {

    @Value("${swagger2.enable}")
    private boolean enable;

    @Bean
    SessionCorrectInterceptor getSessionCorrectInterceptor(){
        return new SessionCorrectInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getSessionCorrectInterceptor())
                .excludePathPatterns("/swagger-ui.html")
                .excludePathPatterns("/doc.html")
                .excludePathPatterns("/v2/api-docs")
                .excludePathPatterns("/druid/**")
                .excludePathPatterns("/swagger-resources/**")
                .excludePathPatterns("/**/swagger-resources/**")
                .excludePathPatterns("/error")
                .excludePathPatterns("/webjars/springfox-swagger-ui/**")
        ;
        super.addInterceptors(registry);
    }


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
        super.addResourceHandlers(registry);
    }


}
